<template>
  <div class="app-container">
    <div class="filter-container">
      <el-form :inline="true" :model="formModel">
        <el-form-item class="no-warn-item" label="工厂:" prop="tmBasPlantId">
          <el-select v-model="formModel.tmBasPlantId" clearable filterable>
            <el-option
              v-for="item in plantOptions"
              :key="item.tmBasPlantId"
              :label="item.plantNo+'-'+item.plantNameC"
              :value="item.tmBasPlantId"
            />
          </el-select>
        </el-form-item>
        <el-form-item class="no-warn-item" label="VIN年份:" prop="vinYearKey">
          <hey-select v-model="formModel.vinYearKey" :clearable="false" clcd="Key_Vin_ModeYear" />
        </el-form-item>
        <el-form-item class="no-warn-item" label="使用状态:" prop="useStatus">
          <hey-select v-model="formModel.useStatus" clcd="vin_num_use_status" />
        </el-form-item>
        <el-row class="submit-area">
          <el-col :span="24">
            <el-button
              v-if="hasPermission('vinSerialNum_select')"
              type="primary"
              plain
              @click="queryList(false)"
            >查询
            </el-button>
            <el-button v-if="hasPermission('vinSerialNum_add')" type="primary" plain @click="handleAdd">新增
            </el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <hey-table ref="table" :table-data="tableData" :columns="columns">
      <template slot="tools">
        <el-table-column
          label="操作"
          width="120"
          fixed="right"
          header-align="center"
          align="center"
        >
          <template slot-scope="{row}">
            <span
              v-if="hasPermission('vinSerialNum_edit')"
              class="hey_tools_btn"
              @click="handleEdit(row)"
            >编辑</span>
            <span
              v-if="hasPermission('vinSerialNum_del')"
              class="hey_tools_btn"
              @click="handleDelete(row)"
            >删除</span>
          </template>
        </el-table-column>
      </template>
    </hey-table>
    <el-dialog
      v-if="dialogVisible"
      v-dialogDrag
      :close-on-click-modal="false"
      title="vin流水号信息"
      :visible.sync="dialogVisible"
      width="60%"
    >
      <VinSerialNum-mnt :page-type="operateType" :edit-data="editData" @mntSuc="queryList" />
    </el-dialog>

  </div>
</template>

<script>

export default {
  name: 'VinSerialNumList',
  components: {
    VinSerialNumMnt: () => import('./vinSerialNum-mnt')
  },
  props: {},
  data() {
    return {
      plantOptions: [],
      dialogVisible: false,
      operateType: '',
      editData: {},
      tableData: [],
      // 查询条件
      formModel: {
        tmBasPlantId: '',
        vinYearKey: '',
        useStatus: ''
      },
      columns: [
        { title: '工厂代码', key: 'plantNo' },
        { title: '工厂名称', key: 'plantNameC' },
        { title: 'VIN年份', key: 'vinYearKey', clcd: 'Key_Vin_ModeYear' },
        { title: '开始序号', key: 'startNo' },
        { title: '当前序号', key: 'currentNo' },
        { title: '最大序号', key: 'maxNo' },

        { title: '使用状态', key: 'useStatus', clcd: 'vin_num_use_status' },
        { title: '创建时间', key: 'createTime' },
        { title: '创建人', key: 'createUsername' },
        { title: '最后修改时间', key: 'lastUpdateTime' },
        { title: '最后修改人', key: 'lastUpdateUsername' }
      ]
    }
  },
  computed: {},
  mounted() {
    this.getPlantOptions()
  },
  methods: {
    // 获取工厂信息列表
    getPlantOptions() {
      const param = {}
      param.isDelete = '0'
      param.status = '1'
      this.get('/tmBasPlant/queryTmBasPlantList', param).then(res => {
        this.plantOptions = res
      })
    },
    queryList() {
      this.$refs.table.query('/vinSerialNum/pageVinSerialNum', this.formModel, '', false)
    },
    handleAdd() {
      this.operateType = 'add'
      this.dialogVisible = true
    },
    handleEdit(row) {
      this.dialogVisible = true
      this.operateType = 'edit'
      this.editData = row || {}
    },
    handleDelete(row) {
      this.$sure('确认删除？', _ => {
        this.post('/vinSerialNum/deleteVinSerialNum', {
          vinSerialNumId: row.vinSerialNumId,
          operateType: '03'
        }).then(_ => {
          this.$info('删除成功', this.queryList)
        })
      })
    }
  }
}
</script>
